package cn.sumpu.app.coolsk.web.mvc.wap;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.sumpu.app.coolsk.biz.ContentBiz;
import cn.sumpu.app.coolsk.biz.HotelRoomBiz;
import cn.sumpu.app.coolsk.biz.MemberBiz;
import cn.sumpu.app.coolsk.biz.OrderBiz;
import cn.sumpu.app.coolsk.biz.ProductBiz;
import cn.sumpu.app.coolsk.biz.ScenicBiz;
import cn.sumpu.app.coolsk.biz.TicketBiz;
import cn.sumpu.app.coolsk.domain.Content;
import cn.sumpu.app.coolsk.domain.Hotel;
import cn.sumpu.app.coolsk.domain.Member;
import cn.sumpu.app.coolsk.domain.OnLineUserListener;
import cn.sumpu.app.coolsk.domain.Order;
import cn.sumpu.app.coolsk.domain.Product;
import cn.sumpu.app.coolsk.domain.ProductPrice;
import cn.sumpu.app.coolsk.domain.Room;
import cn.sumpu.app.coolsk.domain.RoomPrice;
import cn.sumpu.app.coolsk.domain.Scenic;
import cn.sumpu.app.coolsk.domain.Ticket;
import cn.sumpu.app.coolsk.domain.TicketPrice;
import cn.sumpu.app.coolsk.exception.AppBusinessException;
import cn.sumpu.app.coolsk.util.WebUtil;
import cn.sumpu.toolkit.common.page.PageModel;
import cn.sumpu.toolkit.common.util.Common;

@Controller
public class WapController {
	private final static Logger logger = LoggerFactory
	.getLogger(WapController.class);
	@Autowired
	MemberBiz memberBiz;
	@Autowired
	OrderBiz orderBiz;
	@Autowired
	ContentBiz contentBiz;
	@Autowired
	ScenicBiz scenicBiz;
	@Autowired
	TicketBiz ticketBiz;
	@Autowired
	HotelRoomBiz hotelRoomBiz;
	@Autowired
	ProductBiz productBiz;
	/**
	 * wap版本到登陆的页面
	 * @param request
	 * @return
	 * @throws AppBusinessException
	 */
	@RequestMapping(value = "/waptologin.htm")
	public String waptoLogin(HttpServletRequest request) throws AppBusinessException {
		String loginReferer = request.getHeader("referer"); 
		request.getSession().setAttribute("loginReferer", loginReferer);
		return "v1/wap/tologin";
	}
	
	/**
	 * wap版本登陆
	 * @param request
	 * @param response
	 * @param hisUrl
	 * @return
	 */
	@RequestMapping(value = "/waplogin.htm")
	public String wapLogin(HttpServletRequest request,HttpServletResponse response,String hisUrl) {
		try { 
			String ruri = request.getRequestURI();
			String result= memberBiz.login(request,response);
			if("dailylogin".equals(result)){
				String loginReferer = (String)request.getSession().getAttribute("loginReferer");
				if(Common.notEmptyStr(loginReferer) && !"/waptoreg.htm".equals(ruri) && !"/waptologin.htm".equals(ruri) && !"/waplogin.htm".equals(ruri) && !"/wapreg.htm".equals(ruri)){ 
					response.sendRedirect(loginReferer);
				}else{
					response.sendRedirect("wapmember.htm");
				}
			}else if("noRegister".equals(result)){
				request.setAttribute("loginError","登录失败，用户名或密码输入错误或用户名不存在请马上注册");
				return "v1/wap/tologin";
			}
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("/waplogin.htm error",e);
			}
		}
		return null;
	}
	
	/**
	 * wap版本到注册的页面
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/waptoreg.htm")
	public String waptoReg(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String registerReferer = request.getHeader("referer");
		request.getSession().setAttribute("registerReferer", registerReferer);
		return "v1/wap/toreg";
	}
	
	/**
	 * wap版本注册
	 * @param request
	 * @param member
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/wapreg.htm")
	public String wapreg(HttpServletRequest request,Member member, HttpServletResponse response){
		try{
			//注册信息
			//发送验证邮箱
			String path = request.getContextPath();
			String emailPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()+ path + "/";
			member.setRegisterIP(request.getRemoteAddr());
			member.setLoginIP(request.getRemoteAddr());
			//注册
			Member memeberSession = memberBiz.register(emailPath, member);
			request.getSession(true).setAttribute("onlineUser",new OnLineUserListener(memeberSession));
			request.getSession().removeAttribute("accessUser");
			//来源
			String registerReferer = (String)request.getSession().getAttribute("registerReferer");
			if(Common.notEmptyStr(registerReferer)){
				response.sendRedirect(registerReferer);
			}else{
				response.sendRedirect("/wapmember.htm");
			}
		}catch(Exception e){
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("/wapreg.htm error",e);
			}
			return "v1/wap/error";
		}
		
		return null;
	}
	
	/**
	 * wap版本我的主页
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/wapmember.htm")
	public String wapmember(HttpServletRequest request,HttpServletResponse response){
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		try {
			if(onLineUserListener != null && onLineUserListener.getMember() != null){
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				request.setAttribute("member", member);
				return "v1/wap/member";
			}else{
				response.sendRedirect("waplogin.htm");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("/wapmemberdetail.htm error",e);
			}
			return "v1/wap/error";
		}
	}
	
	/**
	 * 个人信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/wapmemberdetail.htm")
	public String wapmemberdetail(HttpServletRequest request,HttpServletResponse response){
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		try {
			if(onLineUserListener != null && onLineUserListener.getMember() != null){
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				request.setAttribute("member", member);
				return "v1/wap/memberdetail";
			}else{
				response.sendRedirect("waplogin.htm");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("/wapmemberdetail.htm error",e);
			}
			return "v1/wap/error";
		}
		
	}
	
	
	/**
	 * wap版本我的订单
	 * @param page
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/wapmyorder.htm")
	public String wapmyOrder(Integer page,HttpServletRequest request,HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		try {
			if(onLineUserListener !=null && onLineUserListener.getMember() != null){
				if (page == null)   
					page = 1;
				Integer pagesize =5;
				PageModel pageModel =orderBiz.getOrderListByMemberId(page, pagesize, onLineUserListener.getMember().getId());
				request.setAttribute("pageModel", pageModel); 
				return "v1/wap/myorder";
			}else{
				response.sendRedirect("waplogin.htm");
				return null;
			}
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "v1/wap/error";
		}
	}
	
	@RequestMapping(value = "/wapmyorderlist.htm")
	public String wapmyorderlist(Integer page,HttpServletRequest request,HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		try {
			if(onLineUserListener !=null && onLineUserListener.getMember() != null){
				if (page == null)   
					page = 1;
				Integer pagesize =5;
				PageModel pageModel =orderBiz.getOrderListByMemberId(page, pagesize, onLineUserListener.getMember().getId()); 
				request.setAttribute("pageModel", pageModel); 
				return "v1/wap/myorderList";
			}else{
				return null;
			}
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "v1/wap/error";
		}
	}
	/**
	 * wap版首页
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/wapindex.htm")
	public String wapindex(HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
//			首页轮播图
			List<Content> cycleList = contentBiz.getContentByChannel("3c838428-67a3-41fc-90ab-192d35267afd", 5);
			request.setAttribute("cycleList", cycleList);
			return "v1/wap/index";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("wapscenic.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	/**
	 * 地图
	 * @param lng
	 * @param lat
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/wapmap.htm")
	public String wapmap(String lng,String lat,HttpServletRequest request,HttpServletResponse response) throws IOException {
		request.setAttribute("lng", lng);
		request.setAttribute("lat", lat);
		return "v1/wap/map";
	}
	
	/**
	 * wap版本的景点门票
	 * @param page
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/wapscenic.htm")
	public String wapScenic(Integer page,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			int pageSize = 5;
			PageModel pageModel = contentBiz.getListViewContentByChannel("f3bfec52-f1df-4e8d-9b1a-18d3d80e63b4", pageSize, page);
			if(pageModel != null){
				List<Content> contentList = pageModel.getList();
				for (Content content : contentList) {
					content.setPriceMin(scenicBiz.getScenicPriceMin(content.getTblId()));
				}
			}
			request.setAttribute("pageModel", pageModel);
			return "v1/wap/scenic";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("wapscenic.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/wapsceniclist.htm")
	public String wapsceniclist(Integer page,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			int pageSize = 5;
//			打折门票下面的热门景区推荐
			PageModel pageModel = contentBiz.getListViewContentByChannel("f3bfec52-f1df-4e8d-9b1a-18d3d80e63b4", pageSize, page);
			if(pageModel != null){
				List<Content> contentList = pageModel.getList();
				for (Content content : contentList) {
					content.setPriceMin(scenicBiz.getScenicPriceMin(content.getTblId()));
				}
			}
			request.setAttribute("pageModel", pageModel);
			return "v1/wap/sceniclist";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("wapscenic.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	/**
	 * wap景点门票详情
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/wapscenicd.htm")
	public String wapscenicd(String id,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			Scenic scenic = scenicBiz.getScenicById(id);
			request.setAttribute("scenic", scenic);
			
			return "v1/wap/scenicd";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("wapscenicd.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	/**
	 * wap景点门票列表
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/waptickets.htm")
	public String waptickets(String id,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			List<Ticket> tList=scenicBiz.getScenicTicket(id); 
			request.setAttribute("tList", tList);
			return "v1/wap/tickets";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("waptickets.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	/**
	 * wap门票详细
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/wapticket.htm")
	public String wapticket(String id,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			Ticket ticket = ticketBiz.getTicketById(id);
			request.setAttribute("ticket", ticket);
			if(ticket != null){
				TicketPrice todayPrice = ticketBiz.getTodayPrice(ticket);
				request.setAttribute("todayPrice", todayPrice);
				
				List<TicketPrice> resPriceList = ticketBiz.resPriceList(ticket);
				request.setAttribute("resPriceList", resPriceList);
				
				
			}else{
				return "v1/wap/error";
			}
			return "v1/wap/ticket";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("wapticket.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	@RequestMapping(value = "/wapticketorder.htm")
	public String wapticketorder(String udate,String tid,HttpServletRequest request,HttpServletResponse response) throws IOException {
		request.setAttribute("udate", udate);
		request.setAttribute("tid", tid);
		try {
			if(Common.empty(tid)){
				return "v1/common/error";
			}else{
				Ticket ticket = ticketBiz.getTicketById(tid);
				request.setAttribute("ticket", ticket);
				
				TicketPrice buytp = ticketBiz.getDayPrice(ticket, udate);
				request.setAttribute("buytp", buytp);
				return "v1/wap/ticketorder";
			}
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("Get ticket failure.", e);
			}
			return "v1/common/error";
		}
	}
	
	@RequestMapping(value = "/wapticketbuy.htm")
	public String wapticketbuy(Integer count,Integer countC,String tid,Order order,HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		try {
			String orderTime = order.getOrderTime();
			if(Common.empty(tid)){
				
			}else{
				Ticket ticket = ticketBiz.getTicketById(tid);
				TicketPrice buytp = ticketBiz.getDayPrice(ticket, orderTime);
				OnLineUserListener onlineUser =  (OnLineUserListener) request.getSession().getAttribute("onlineUser");
				orderBiz.saveOrder(order, ticket, buytp, count,countC, onlineUser.getMember());
				response.sendRedirect("wapmyorder.htm");
			}
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("Get ticket failure.", e);
			}
		}
		return null;
	}
	
	/**
	 * wap版本的度假酒店
	 * @param page
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/waphotel.htm")
	public String wapHotel(Integer page,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			int pageSize = 5;
			PageModel pageModel = contentBiz.getListViewContentByChannel("9adb2f45-399b-4aec-b6ba-a4994c62b464", pageSize, page,true);
			if(pageModel != null){
				List<Content> contentList = pageModel.getList();
				for (Content content : contentList) {
					Hotel hotel = hotelRoomBiz.getHotelById(content.getTblId());
					if(hotel != null){
						content.setPriceMin(hotel.getMinPrice());
					}
					
				}
			}
			request.setAttribute("pageModel", pageModel);
			return "v1/wap/hotel";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("waphotel.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/waphotelist.htm")
	public String waphotelist(Integer page,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			int pageSize = 5;
//			特惠酒店下面的热榜酒店
			PageModel pageModel = contentBiz.getListViewContentByChannel("9adb2f45-399b-4aec-b6ba-a4994c62b464", pageSize, page,true);
			if(pageModel != null){
				List<Content> contentList = pageModel.getList();
				for (Content content : contentList) {
					Hotel hotel = hotelRoomBiz.getHotelById(content.getTblId());
					if(hotel != null){
						content.setPriceMin(hotel.getMinPrice());
					}
					
				}
			}
			request.setAttribute("pageModel", pageModel);
			return "v1/wap/hotelist";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("waphotel.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	
	/**
	 * 酒店详细页面
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/waphoteld.htm")
	public String waphoteld(String id,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			Hotel hotel = hotelRoomBiz.getHotelById(id);
			request.setAttribute("hotel", hotel);
			return "v1/wap/hoteld";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("waprooms.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	/**
	 * wap版本的酒店的房间列表
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/waprooms.htm")
	public String waprooms(String id,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			List<Room> rooms = hotelRoomBiz.getHotelRoom(id);
			request.setAttribute("rooms", rooms);
			return "v1/wap/rooms";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("waprooms.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	
	@RequestMapping(value = "/waproomorder.htm")
	public String waproomorder(String rid,HttpServletRequest request,HttpServletResponse response) throws IOException {
		String udate = Common.getFormatDate(new Date(), "yyyy-MM-dd");
		request.setAttribute("udate",udate); 
		request.setAttribute("rid", rid);
		try {
			if(memberBiz.checkMemberLogin(request)){
				Room room=hotelRoomBiz.getRoomById(rid);
				if(room != null){
					Hotel hotel=hotelRoomBiz.getHotelById(room.getHotel());
					request.setAttribute("hotel", hotel);
					request.setAttribute("room", room);
					RoomPrice roomPrice=hotelRoomBiz.getRoomDayPrice(room, udate);
					request.setAttribute("roomPrice", roomPrice);
					
					List<RoomPrice> resPriceList = hotelRoomBiz.resRoomPriceList(rid);
					request.setAttribute("resPriceList", resPriceList);
				}
				
				return "v1/wap/roomorder";
			}else{
				return "v1/wap/error";
			}
		} catch (Exception e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("Book hotel order failure.", e);
			}
			return "v1/wap/error";
		}	
		
	}
	
	@RequestMapping(value = "/waproombuy.htm")
	public String waproombuy(String udate,int days,String rid,Order order,HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		int count = 1;
		order.setOrderTime(udate);
		try {
			if(memberBiz.checkMemberLogin(request)){
				Room room=hotelRoomBiz.getRoomById(rid); 
				request.setAttribute("room", room);
				RoomPrice buyrp = hotelRoomBiz.getRoomDayPrice(room,udate);
				OnLineUserListener onlineUser =  (OnLineUserListener) request.getSession().getAttribute("onlineUser");
				String ldate = WebUtil.addDate(udate, days);
				Order orderSave = orderBiz.saveOrder(order, room, buyrp, count, onlineUser.getMember(),ldate);
				request.setAttribute("orderSave", orderSave);
				request.setAttribute("count", count);
				request.setAttribute("udate", udate);
				response.sendRedirect("wapmyorder.htm");
				return null;
			}else{
				return "v1/wap/error";
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("bookRoom failure.", e);
			}
			return "v1/common/error";
		}	
		
	}
	
	/**
	 * wap版本的线路推荐
	 * @param page
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/wapline.htm")
	public String wapLine(Integer page,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			int pageSize = 5;
			PageModel pageModel = contentBiz.getListViewContentByChannel("2a2be9e2-42ff-456c-a60c-c0d737e20fb8", pageSize, page,true);
			if(pageModel != null){
				List<Content> contentList = pageModel.getList();
				for (Content content : contentList) {
					Product product = productBiz.getProductById(content.getTblId());
					if(product != null){
						content.setPriceMin(product.getPriceMin());
					}
					
				}
			}
			request.setAttribute("pageModel", pageModel);
			return "v1/wap/line";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("wapline.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/waplinelist.htm")
	public String waplinelist(Integer page,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			int pageSize = 5;
//			线路推荐下的推荐线路图
			PageModel pageModel = contentBiz.getListViewContentByChannel("2a2be9e2-42ff-456c-a60c-c0d737e20fb8", pageSize, page,true);
			if(pageModel != null){
				List<Content> contentList = pageModel.getList();
				for (Content content : contentList) {
					Product product = productBiz.getProductById(content.getTblId());
					if(product != null){
						content.setPriceMin(product.getPriceMin());
					}
					
				}
			}
			request.setAttribute("pageModel", pageModel);
			return "v1/wap/linelist";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("wapline.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	/**
	 * 线路推荐详细页面
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/wapproduct.htm")
	public String wapproduct(String id,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			Product product = productBiz.getProductById(id);
			request.setAttribute("product", product);
			return "v1/wap/product";
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("wapproduct.htm error", e);
			}
			return "v1/wap/error";
		}
	}
	
	@RequestMapping(value = "/wapproductorder.htm")
	public String wapproductorder(String id,HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			Product product = productBiz.getProductById(id);
			request.setAttribute("product", product);
			if(product != null){
				ProductPrice todayPrice = productBiz.getTodayPrice(product); 
				request.setAttribute("todayPrice", todayPrice);
				
				List<ProductPrice> resPriceList = productBiz.resPriceList(product);
				request.setAttribute("resPriceList", resPriceList);
				if(resPriceList!=null && resPriceList.size() > 0){
					int nowMonth = WebUtil.getNowMonth(resPriceList.get(0).getSpDate());
					int nextMonth = WebUtil.getNextMonth(resPriceList.get(0).getSpDate());
					request.setAttribute("nowMonth", nowMonth);
					request.setAttribute("nextMonth", nextMonth);
				}
			}
			
			return "v1/wap/productorder";
		} catch (Exception e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("Book hotel order failure.", e);
			}
			return "v1/wap/error";
		}	
		
	}
	
	@RequestMapping(value = "/wapproductbuy.htm")
	public String wapproductbuy(int count,String pid,Order order,HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		try {
			if(Common.empty(pid)){
				return "v1/wap/error";
			}else{
				Product product = productBiz.getProductById(pid);
				OnLineUserListener onlineUser =  (OnLineUserListener) request.getSession().getAttribute("onlineUser");
				orderBiz.saveOrder(order, product,  count, onlineUser.getMember());
				response.sendRedirect("wapmyorder.htm");
				return null;
			}
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("Get ticket failure.", e);
			}
			return "v1/wap/error";
		}
		
	}
	
	@RequestMapping(value = "/wapmore.htm")
	public String wapmore(HttpServletRequest request,HttpServletResponse response) throws IOException {
			return "v1/wap/more";
	}
	
}
